/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db_interaction;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.Session;

/**
 *
 * @author Neves
 */
@Entity
@Table(name = "ranking")
public class Ranking implements Serializable {

    @Id
    @GeneratedValue
    private int Ranking_id;
    @Basic
    @Column(name = "Ranking_Publicacao_id")
    private int Ranking_Publicacao_id;
    @Basic
    @Column(name = "Ranking_Utilizador_id")
    private int Ranking_Utilizador_id;
    @Basic
    @Column(name = "Ranking_Ranking_desc_id")
    private int Ranking_Ranking_desc_id;
    @Basic
    @Column(name = "Ranking_activo")
    private boolean Ranking_activo;

    //GETS
    public int GETRanking_id() {
        return this.Ranking_id;
    }

    public int GETRanking_Publicacao_id() {
        return this.Ranking_Publicacao_id;
    }

    public int GETRanking_Utilizador_id() {
        return this.Ranking_Utilizador_id;
    }

    public int GETRanking_Ranking_desc_id() {
        return this.Ranking_Ranking_desc_id;
    }

    public boolean GETRanking_Ranking_activo() {
        return this.Ranking_activo;
    }

    //SETS
    public void SETRanking_id(int Ranking_id) {
        this.Ranking_id = Ranking_id;
    }

    public void SETRanking_Publicacao_id(int Ranking_Publicacao_id) {
        this.Ranking_Publicacao_id = Ranking_Publicacao_id;
    }

    public void SETRanking_Utilizador_id(int Ranking_Utilizador_id) {
        this.Ranking_Utilizador_id = Ranking_Utilizador_id;
    }

    public void SETRanking_Ranking_desc_id(int Ranking_Ranking_desc_id) {
        this.Ranking_Ranking_desc_id = Ranking_Ranking_desc_id;
    }

    public void SETRanking_Ranking_activo(boolean Ranking_activo) {
        this.Ranking_activo = Ranking_activo;
    }

    //DB access
    public int insertEntity(Ranking rk) {
        //returns 1 if successfull
        //return -1 if error
        try {
            Session s = NewHibernateUtil.getSessionFactory();
            s.save(rk);
            s.getTransaction().commit();
            System.out.println("Inserido");
            return 1;
        } catch (Exception e) {
            return -1;
        }
    }

    public Ranking SelectEntity(Ranking rk) {
        Ranking rank = null;

        //returns sellected friend if successfull
        //return null
        try {
            Session s = NewHibernateUtil.getSessionFactory();
            rank = (Ranking) s.load(Ranking.class, rank.GETRanking_id());
            s.getTransaction().commit();
            return rank;

        } catch (Exception e) {
            return rank;
        }
    }

    public int UpdateEntity(Ranking rk) {
        //returns 1 if successfull
        //return -1 if error
        try {
            Session s = NewHibernateUtil.getSessionFactory();
            s.save(rk);
            s.getTransaction().commit();
            return 1;

        } catch (Exception e) {
            return -1;
        }
    }
}
